package com.hsy.sunflowerbao.home.ui

import android.support.v7.widget.RecyclerView
import android.view.ViewGroup
import com.flux.ui.adapter.FActivityRecycleAdapter
import com.hsy.sunflowerbao.R
import com.hsy.sunflowerbao.base.data.TagData
import com.hsy.sunflowerbao.base.ui.adapter.BaseHolder
import kotlinx.android.synthetic.main.item_tag.view.*
import java.lang.ref.WeakReference

/**
 * Created on 2018/4/11.
 *
 * @author Yang
 */
class TagAdapter(activity: ScoreActivity, var items: List<TagData>) : FActivityRecycleAdapter<ScoreActivity>(WeakReference(activity)) {

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = BaseHolder(getItemView(R.layout.item_tag, parent))

    override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
        holder.itemView.tagItem.text = items[position].name
        holder.itemView.tagItem.setOnClickListener {
            it.isSelected = !it.isSelected
            if (it.isSelected) mActivity.get()?.tags?.add(items[position].id)
            else mActivity.get()?.tags?.remove(items[position].id)
        }
    }

    override fun getItemCount() = items.size
}